package org.example.myleet.p909;

import org.example.myleet.Utils.Assert;
import org.example.myleet.Utils.JsonUtils;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        Solution solution = new Solution();
        Assert.isTrue(4 == solution.snakesAndLadders(parse("[\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,35,-1,-1,13,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,15,-1,-1,-1,-1]]\n")));
        Assert.isTrue(-1 == solution.snakesAndLadders(parse("[\n" +
                "[30,-1,-1,-1,-1,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,35,-1,-1,13,-1],\n" +
                "[-1,-1,-1,-1,-1,-1],\n" +
                "[-1,15,-1,-1,-1,-1]]\n")));
        Assert.isTrue(6 == solution.snakesAndLadders(parse("[" +
                "[-1,-1,5,4,3,2]," +
                "[-1,-1,-1,-1,-1,1]," +
                "[-1,-1,-1,-1,-1,-1]," +
                "[-1,26,-1,-1,13,-1]," +
                "[-1,-1,-1,-1,-1,-1]," +
                "[-1,15,-1,-1,-1,-1]]")));
        Assert.isTrue(2 == solution.snakesAndLadders(parse("[" +
                "[-1,-1,19,10,-1]," +
                "[2,-1,-1,6,-1]," +
                "[-1,17,-1,19,-1]," +
                "[25,-1,20,-1,-1]," +
                "[-1,-1,-1,-1,15]]")));
    }

    private static int[][] parse(String input) {
        List<List<Integer>> parsed = JsonUtils.parse(input, List.class);
        int i = 0;
        int[][] result = new int[parsed.size()][parsed.get(0).size()];
        for (List<Integer> list : parsed) {
            int j = 0;
            for (Integer integer : list) {
                result[i][j++] = integer;
            }
            ++i;
        }
        return result;
    }
}
